<?php

namespace App\Remote\Orm;

use Closure;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class Remote extends \App\Remote\Remote
{
    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return config('orm.domain');
    }

    /**
     * @return array
     */
    public static function buildBasicHeaders(): array
    {
        return [
            'Content-Type'   => "application/json",
            'internal-key'   => config('orm.internalKey'),
            'internal-token' => config('orm.internalValue'),
        ]; // TODO: Change the autogenerated stub
    }

    public static function registerResponseHandle(): Closure
    {
        return function ($responseHttpCode, $responseOriginalContents) {
            if (
                $responseHttpCode == ResponseAlias::HTTP_OK
                &&
                $parsedResponse = jsonToArr($responseOriginalContents, [])
            ) {
                if (attributeGet($parsedResponse, "code", null) == 0) {
                    return attributeGet($parsedResponse, "data", "");
                }
            }
            throw new \Exception($responseOriginalContents);
        }; // TODO: Change the autogenerated stub
    }
}
